<?php

/***  DOCUMENTATION LAYER

Ceo Unit Testing

Last Update: Sep 2007
	
DESCRIPTION
	this is a group of SimpleTest unit tests called by TestSuite class in
  concept.simpletestgroup.php file
	
NOTES
		
***/

// load classes to be tested
# loaded in setup
global $PROJECT, $CeoObj;  // must declare global here as this has internal scope
require_once('../www/ceo.project_driver.inc.php');
$debug = 0;  
$CeoObj = new CeoFramework($debug);
$CeoObj->PATH['datasafe'] = $CeoObj->super_root . '__DEV'.$CeoObj->DS.'nudgewink.inc.php';
$CeoObj->Err->filter_trivial = 1;    
$CeoObj->load_framework();
$CeoObj->load_ext('in');    


// Basic Form
class BasicForm extends UnitTestCase 
{
  function setUp()
  {
    global $CeoObj;
    $this->Ceo = $CeoObj;
    $this->Ceo->Form = new CeoForm($this->Ceo->debug);
    $this->Ceo->Form->add_element($name='text_input', $type='input_text', $label='input some text', $is_required=1, $maxlength=255, $minlength=4);
	  $this->Ceo->Form->add_element($name='email_input', $type='input_email',$label='email address', $is_required=1);
	  $this->Ceo->Form->add_element($name='url_input', $type='input_url',$label='web address', $is_required=0);
  }
  
  function tearDown() {}

  function testCeoCx()
  {
    $this->assertTrue(is_object($this->Ceo));
  }
  
  function testFormCx()
  {
    $this->assertTrue(is_object($this->Ceo->Form));
  }
  
  function testFormElementCx()
  {
    $this->assertTrue(is_object($this->Ceo->Form->EL['text_input']));
  }
  
  function testFormElementInvalid()
  {
    @$this->Ceo->Form->add_element($name='error_test', $type='unknown',$label='deliberate error', $is_required=0);
    $this->assertFalse(is_object($this->Ceo->Form->EL['error_test']));
  }
}



// Basic Form
class FormValidation extends UnitTestCase 
{
  function setUp()
  {
  }
  
  function tearDown() {}
  
  function testIsSubmitted()
  {
  }

  function testValidEmail()
  {
    $_POST['valid_email'] = 'john@test.com';  
    global $CeoObj;
    $this->Ceo = $CeoObj;
    $this->Ceo->Form = new CeoForm($this->Ceo->debug);
	  $this->Ceo->Form->add_element($name='valid_email', $type='input_email',$label='email address', $is_required=1);
    $this->Ceo->Form->add_element($name='invalid_email', $type='input_email',$label='email address', $is_required=1);
    $this->assertTrue($this->Ceo->Form->EL['valid_email']->is_valid());
  }
  
  function testInvalidEmail()
  {
    $_POST['invalid_email'] = 'not an email address';
    global $CeoObj;
    $this->Ceo = $CeoObj;
    $this->Ceo->Form = new CeoForm($this->Ceo->debug);
	  $this->Ceo->Form->add_element($name='valid_email', $type='input_email',$label='email address', $is_required=1);
    $this->Ceo->Form->add_element($name='invalid_email', $type='input_email',$label='email address', $is_required=1);
    $this->assertTrue(!$this->Ceo->Form->EL['invalid_email']->is_valid());
  }
}



?>
